Homework Assignment 1 (Individual)¶

Git practice, debugging practice, and new Python packages¶

✅ Aryan Dhar

¶

✅ aryandhr

¶

Goals for this homework assignment¶

By the end of this assignment, you should be able will:

  • Demonstrate the purpose and utility of Git and demonstrate a workflow in practice.
  • Use Git to create a repository, track changes to the files within the repository, and push those changes to a remote repository.
  • Articulate the most common debugging strategies
  • Debug some basic Python code.
  • Read documentation and example code to use a new Python package

Work through the following assignment, making sure to follow all of the directions and answer all of the questions.

There are 100 points possible on this assignment. Point values for each part are included in the section headers and question prompts.

This assignment is due roughly two weeks from now at 11:59 pm on Friday, February 3rd. It should be uploaded into the "Homework Assignments" submission folder for Homework #1 on D2L. Submission instructions can be found at the end of the notebook.

Part 0: Office Hours and Academic Integrity (10 points)¶

Academic integrity statement (2 Points)¶

In the markdown cell below, paste your personal academic integrity statement. By including this statement, you are confirming that you are submitting this as your own work and not that of someone else.

"As a Spartan, I shall work to uphold the highest moral principles. I will strive to be honest in my work and in my interactions with others. I will also take delight in the knowledge that honor is more important than grades. After I graduate from Michigan State University, I'll continue to uphold these ideals and work to develop my personal integrity in whatever I do.

Going to Office Hours (8 Points)¶

Why are we doing this?¶

We want to make sure that everyone knows how to access the resources available to you. One of the best resources you have at your disposal is office hours.

What will you do?¶

(At minimum) Go to one office hour session ​(it doesn’t matter which one you go to). Come with one question that you would like to talk about. It can be big or small. Ask your question. All of the instructors for CMSE 202 (section leads, TAs, and LAs) will be adding to a running list of folks that we see during office hours; as long as your name appears on the list, you’ll get credit for this part of Homework 1.

NOTE: The day when the homework is due (Friday, February 3rd) will be the busiest time for folks to go to office hours. You are STRONGLY encouraged to go to office hours before Friday to get credit for this part of this assignment. (You should still feel free to go to office hours on Friday for help, though!)

You can find the office hours calendar on the course website.

✅ Question 0.1 (8 points)****

Type below the question you asked.

Were you born on a Friday?

Part 1: Designing a Workflow with Git (30 points total)¶

You have spent some time in class learning about how/why we use git in CMSE 202 and beyond, and you will be expected to use it throughout the semester.

1.1 Propose a Software Development Workflow (10 points)¶

You are working collaboratively with a team on a research project that includes developing code as well as writing a paper to communicate your results, and you need to ensure that all work is managed and tracked with git. Since you are learning about git in your class, your groupmates have asked you to propose a software development workflow for this project. Here, workflow is defined as the process by which the project is managed and developed.

Your workflow must (at least) handle the following:

  1. What role (or roles) will each person have?
  2. How will changes be made/tracked?
  3. What are your requirements for commit messages?
  4. How do you expect people to work on their portions of the projects (using branches/merges)?

In the cell below, write down the guidelines for your proposed workflow, making sure to account for all of the items mentioned above.

  1. Every person will be a collaborator on the project, that could be either developing code, dicussing ideas, doing research, or writing the paper, everyone will encourage each other and make sure to pull their own weight.
  2. Changes to the codebase will be tracked with git. Every team member is expected to pull from the remote repo as often as possible and don't forget to add, commit, and push (in order)!
  3. Commit messages should be brief but descriptive. Treat it like a tiny docstring telling the rest of the team what you changed and/or added with your new commit.
  4. Team members are expected develop in their personal branches and create a pull request once they are done so that all the other developers can review the code before deciding to merge it.

1.2 Testing Your Workflow (10 points)¶

In the cell(s) below, demonstrate that your workflow works by performing (or answering) the following tests:

  1. A new person is joining your team, but they have never coded before and are concerned about making changes that might break your code. According to your workflow, what should their role be, and how should they make changes to the code?
  2. Using vi (or your favorite text editor), create a file called paper_draft.txt. Following your workflow, make and commit changes to that file. Copy and paste any command line interface commands you use in the cell below.
  1. Being someone who has never coded before, their role should consist of doing as little as possible development and more towards doing research, writing the paper, and discussing ideas with those who can code and see if it could be implemented in the project.
In [1]:
# put any code here (feel free to add additional cells)
git clone https://github.com/aryandhr/CMSE202-s23-turnin
touch paper_draft.txt
vi paper_draft.txt
# inserted proposed workflow into text file.
git add paper_draft.txt
git commit -m "Initial commit - proposed workflow"
git push origin main
  File "<ipython-input-1-91fc3c169e87>", line 2
    git clone https://github.com/aryandhr/CMSE202-s23-turnin
        ^
SyntaxError: invalid syntax

1.3 Reflecting (10 points)¶

Answer the following questions in the cell below about your workflow:

  1. What challenges/bugs did you run into when testing your workflow? How might you design for them in the future?
  2. What worked well with your workflow?
  1. I did not make a new branch because I was just creating a text file and not writing any code. However, in the future, it might be better to specify that creating new branches is really only necessary if you are writing a script.
  2. It was good to write "add commit and push (in order)" in the workflow as it reminds you the steps to take in order.

🛑 STOP COMMIT YOUR WORK TO GIT NOW¶

You should commit early and often, but at least do it after you complete each homework problem.

Make sure to use meaningful commit messages that indicate the changes you have made!

Part 2: Debugging Code (30 points total)¶

Bugs are a part of life in writing code. They do not mean you are not making progress at coding. However, you can employ various debugging strategies to help you work through bugs efficiently and confidently.

2.1 Helping a CMSE 201 Student (10 points)¶

In the cell below, explain debugging to a CMSE 201 student, and describe the process you would recommend they use to debug their code. You must include how you would solve the various types of bugs you can encounter while coding. Remember all of the resources you can use in CMSE 201/202 (particularly Google or other search engines!).

My first step when debugging is thinking about what I want my code to do, and then think about what it is currently doing. Using the dubgger in VSCode is a great tool to see what values your variables are taking, how they are getting updated as your code runs, what exactly your functions are outputting and much more. One debugging tool I have recently discovered is pythontutor which a website where you can run your Python code and it takes you step by step through the code and tells you what each line is doing. It is always okay to Google your errors, ask for help on Slack, go to helprooms. However, it is not okay to plagiarize code and let someone else fix your code. You must understand why your code isn't working and then fix the problem.

2.2 Working Through Bugs (20 points total)¶

2.2.1 A Squirrelly Situation (10 points)¶

Run the code in the cell below. There are (at least) 2 bugs to find and fix! Complete the following questions:

  1. Apply your debugging process to solve the bug(s) (showing the corrected code).
  2. Did your process work? If so, continue to the next problem. If not, describe why and indicate any changes you would make to your process.
In [2]:
import numpy as np # import modules at the top to avoid issues later when debugging

# function that returns a random number of squirrels spotted between 0 and the limit
def squirrel_spotting_simulation(limit=15):
    random_squirrels = np.random.randint(limit)
    return random_squirrels

# initialize number of squirrels
squirrel_count = 0
# initialize number of time steps
t = 0

# loop until the observer reaches a maximum of 100 squirrels spotted
while squirrel_count <= 100:
    # use our function to generate a random number of squirrels spotted
    increment = squirrel_spotting_simulation(15)
    # increment the number of time steps by 1
    t+=1
    # add the number of random squirrels this time step to the total number
    squirrel_count+=increment

# print the total number of timesteps it took
print(t)
14

Yes, the debugging process worked. It was easier to visualize once I run it locally in VSCode.

2.2.2 Plotting and Scheming¶

Run the code in the cell below, then answer the following questions: set_xlabel vs. label

  1. Apply your debugging process to solve the bug (showing the corrected code).
  2. Did your process work? If so, continue to the next problem. If not, describe why and indicate any changes you would make to your process.
In [3]:
# code to plot two randomly generated data sets (sin and cos) on one plot

import matplotlib.pyplot as plt
import numpy as np

# generate some x data: sixty data points from 0 to 4π
x_sin = np.linspace(0,4*np.pi,60)

# generate some y data: 1.5 * sin(1.2x + 0.5)
# we add the np.random.normal(0.25,.25,60) at the end to add some randomness to the data
y_sin = 1.5 * np.sin(1.2 * x_sin + 0.5) + np.random.normal(.25,.25,60)

y_cos = 1.5 * np.cos(1.2 * x_sin + 0.5) + np.random.normal(.25,.25,60)
# plot our data
plt.scatter(x_sin, y_sin, label = "sin data")
plt.xlabel('x')
plt.ylabel('y')
plt.scatter(x_sin, y_cos, label = "cos data")
plt.legend()
Out[3]:
<matplotlib.legend.Legend at 0x7f5c0b9cb5b0>

The set_xlabel method, as follows from its name, sets the label for the x axis. In this example, we have it set as "x". The label attribute on the other hand, "labels" our graph with the string we provide it with. Here, we have two plots and we use the label attribute in both, appropriately, to name each set's data. It is important to include the plt.legend() statement to actually see these labels.

🛑 STOP COMMIT YOUR WORK TO GIT NOW¶

You should commit early and often, but at least do it after you complete each homework problem.

Part 3: New Packages (25 points total)¶

In Part 1, you developed a workflow for the project your team is working on. One of your team members found this package that will help with some of the visualizations, however you discover that you don't currently have this package installed.

A quick Google search tells you that the plotly Python library is an interactive, open-source plotting library that supports over 40 unique chart types covering a wide range of statistical, financial, geographic, scientific, and 3-dimensional use-cases. Sounds great, let's figure this out!

3.1 Install Package using CLI¶

You remember from class that you can install packages using the command line. Using your terminal, install the plotly package, then answer the following questions.

3.1.1 (5 points):¶

In the cell below, write down the command you used to install the package.

pip install plotly==5.13.0 # accessed from plotly documentation @ https://plotly.com/python/getting-started/

IMPORTANT NOTE¶

Particularly if you are using JupyterHub, you may get a message similar to this one in your terminal:

package_exists.jpg

This means that the package has already been installed. If that is the case, you still need to provide the command you would use to install the package above, and then proceed to the rest of this problem.

3.2 Reading Package Documentation¶

Now that you've installed Plotly, its time to explore the package! What can this package do? The best place to find this information is in the documentation.

3.2.1 (10 points):¶

Answer the following questions:

  1. What kind of package is Plotly? (e.g. Mathematical, Graphing, Statistical, etc.)?
  2. How many different tabs exist in the Plotly Open Source Graphing Libraries?
  3. When would you use Plotly?
  4. Are there any packages you know that are similar to plotly?
  5. What are some different charts/plots you can create with Plotly?
  1. Plotly is a package that supports over 40 different types of graphing charts.
  2. There are 8 tabs for what I assume are 8 different languages.
  3. You would use Plotly when you want to plot graphs for an easier visualization of your data.
  4. Matplotlib and seaborn.
  5. You could create bar charts, scatter plots, pie charts and so much more.

3.3 Using The New Package¶

Finally, it's time to use the newly installed package! Pick a dataset from the data package that is a part of Plotly.

3.3.1 (10 points):¶

Create a graph using one of these datasets. You can use the documentation for inspiration, but try to change the variables around so you get to really experience the package! Make sure to include titles and axis labels!

In [4]:
import plotly.express as px

df = px.data.stocks()
fig = px.line(df, y=df['MSFT'], x=df["date"], title='Microsoft Stock closing prices from 2018/2019')
fig.show()

Part 4: Finishing (5 points)¶

✅ Have you put your name and GitHub username at the top of your notebook?

Yes

✅ Have you added the TA and Instructor to your GitHub repository?

Yes

✅ Merge your homework_01 branch into the main branch and checkout the main branch

# Put the command you used to merge your branch here

git merge homework_01 main

✅ Push your repository to GitHub.

# Put the command you used to push to GitHub here

git push origin main

NOTE: The grader is able to see your commit messages, branches and whether you pushed the repo at this stage.


Assignment wrap-up¶

Congratulations, you're done!¶

Submit this assignment by uploading it to the course Desire2Learn web page. Go to the "Homework Assignments" folder, find the dropbox link for Homework #1, and upload it there.

© Copyright 2023, Department of Computational Mathematics, Science and Engineering at Michigan State University